package com.jingdianjichi.subject.domain.Handler.subject;

import com.jingdianjichi.subject.common.enums.IsDeletedCodeEnum;
import com.jingdianjichi.subject.common.enums.SubjectInfoTypeCodeEnum;
import com.jingdianjichi.subject.domain.entity.SubjectAnswerBo;
import com.jingdianjichi.subject.domain.entity.SubjectInfoBo;
import com.jingdianjichi.subject.infra.basic.entity.SubjectJudge;
import com.jingdianjichi.subject.infra.basic.service.SubjectJudgeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class JudgeTypeHandler implements SubjectTypeHandler {

    @Resource
    SubjectJudgeService subjectJudgeService;
    @Override
    public SubjectInfoTypeCodeEnum getHandlerType() {
        return SubjectInfoTypeCodeEnum.JUDGE;
    }

    @Override
    public void add(SubjectInfoBo subjectInfoBO) {
        //判断题目的插入
        SubjectJudge subjectJudge = new SubjectJudge();
        SubjectAnswerBo subjectAnswerBO = subjectInfoBO.getOptionList().get(0);
        subjectJudge.setSubjectId(subjectInfoBO.getId());
        subjectJudge.setIsCorrect(subjectAnswerBO.getIsCorrect());
        subjectJudge.setIsDeleted(IsDeletedCodeEnum.UN_DELETED.getCode());
        subjectJudgeService.insert(subjectJudge);
    }

//    @Override
//    public SubjectOptionBO query(int subjectId) {
//        SubjectJudge subjectJudge = new SubjectJudge();
//        subjectJudge.setSubjectId(Long.valueOf(subjectId));
//        List<SubjectJudge> result = subjectJudgeService.queryByCondition(subjectJudge);
//        List<SubjectAnswerBO> subjectAnswerBOList = JudgeSubjectConverter.INSTANCE.convertEntityToBoList(result);
//        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
//        subjectOptionBO.setOptionList(subjectAnswerBOList);
//        return subjectOptionBO;
//    }

}
